/*   1:    */ package org.intellij.plugins.relaxNG.compact.parser;
/*   2:    */ 
/*   3:    */

import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiBuilder.Marker;
import com.intellij.psi.tree.IElementType;
import org.intellij.plugins.relaxNG.compact.RncElementTypes;
import org.intellij.plugins.relaxNG.compact.RncTokenTypes;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */ 
/*  10:    */ public abstract class DeclarationParsing
/*  11:    */   extends AbstractParsing
/*  12:    */ {
/*  13:    */   public DeclarationParsing(PsiBuilder paramPsiBuilder)
/*  14:    */   {
/*  15: 33 */     super(paramPsiBuilder);
/*  16:    */   }
/*  17:    */   
/*  18:    */   protected void parseTopLevel()
/*  19:    */   {
/*  20: 37 */     while ((!this.myBuilder.eof()) && (LA_DECL.contains(currentToken()))) {
/*  21: 38 */       parseDecl(this.myBuilder);
/*  22:    */     }
/*  23:    */     PsiBuilder.Marker localMarker;
/*  24: 41 */     if (LA_GRAMMAR_CONTENT.contains(currentToken()))
/*  25:    */     {
/*  26: 42 */       localMarker = this.myBuilder.mark();
/*  27: 43 */       parseGrammarContents();
/*  28: 44 */       localMarker.done(RncElementTypes.GRAMMAR_PATTERN);
/*  29:    */     }
/*  30: 45 */     else if (currentToken() == RncTokenTypes.KEYWORD_GRAMMAR)
/*  31:    */     {
/*  32: 46 */       parsePattern();
/*  33:    */     }
/*  34:    */     else
/*  35:    */     {
/*  36: 48 */       localMarker = this.myBuilder.mark();
/*  37: 49 */       while (!this.myBuilder.eof()) {
/*  38: 50 */         if (!parsePattern()) {
/*  39:    */           break;
/*  40:    */         }
/*  41:    */       }
/*  42: 54 */       localMarker.done(RncElementTypes.GRAMMAR_PATTERN);
/*  43:    */     }
/*  44:    */   }
/*  45:    */   
/*  46:    */   protected abstract boolean parsePattern();
/*  47:    */   
/*  48:    */   protected void parseGrammarContents()
/*  49:    */   {
/*  50: 61 */     while (LA_GRAMMAR_CONTENT.contains(currentToken())) {
/*  51: 62 */       a(true);
/*  52:    */     }
/*  53:    */   }
/*  54:    */   
/*  55:    */   private void a()
/*  56:    */   {
/*  57: 67 */     while (LA_INCLUDE_CONTENT.contains(currentToken())) {
/*  58: 68 */       a(false);
/*  59:    */     }
/*  60:    */   }
/*  61:    */   
/*  62:    */   private void a(boolean paramBoolean)
/*  63:    */   {
/*  64: 73 */     IElementType localIElementType = currentToken();
/*  65: 74 */     if (localIElementType == RncTokenTypes.KEYWORD_START)
/*  66:    */     {
/*  67: 75 */       e();
/*  68:    */     }
/*  69: 76 */     else if (localIElementType == RncTokenTypes.KEYWORD_DIV)
/*  70:    */     {
/*  71: 77 */       d();
/*  72:    */     }
/*  73: 78 */     else if ((paramBoolean) && (localIElementType == RncTokenTypes.KEYWORD_INCLUDE))
/*  74:    */     {
/*  75: 79 */       c();
/*  76:    */     }
/*  77: 80 */     else if (RncTokenTypes.IDENTIFIERS.contains(localIElementType))
/*  78:    */     {
/*  79: 81 */       b();
/*  80:    */     }
/*  81:    */     else
/*  82:    */     {
/*  83: 83 */       error("Unexpected token");
/*  84: 84 */       advance();
/*  85:    */     }
/*  86:    */   }
/*  87:    */   
/*  88:    */   private void b()
/*  89:    */   {
/*  90: 89 */     PsiBuilder.Marker localMarker = begin();
/*  91: 90 */     match(ASSIGN_METHOD, "'=', '|=' or '&=' expected");
/*  92: 91 */     if (!parsePattern()) {
/*  93: 92 */       error("Pattern expected");
/*  94:    */     }
/*  95: 94 */     localMarker.done(RncElementTypes.DEFINE);
/*  96:    */   }
/*  97:    */   
/*  98:    */   private void c()
/*  99:    */   {
/* 100: 98 */     PsiBuilder.Marker localMarker = begin();
/* 101:    */     
/* 102:100 */     parseAnyUriLiteral();
/* 103:    */     
/* 104:102 */     parseInherit();
/* 105:104 */     if (matches(RncTokenTypes.LBRACE))
/* 106:    */     {
/* 107:105 */       a();
/* 108:106 */       match(RncTokenTypes.RBRACE, "'}' expected");
/* 109:    */     }
/* 110:108 */     localMarker.done(RncElementTypes.INCLUDE);
/* 111:    */   }
/* 112:    */   
/* 113:    */   protected final void parseAnyUriLiteral()
/* 114:    */   {
/* 115:112 */     match(RncTokenTypes.LITERAL, "URI literal expected");
/* 116:    */   }
/* 117:    */   
/* 118:    */   protected final void parseInherit()
/* 119:    */   {
/* 120:116 */     if (matches(RncTokenTypes.KEYWORD_INHERIT))
/* 121:    */     {
/* 122:117 */       match(RncTokenTypes.EQ, "'=' expected");
/* 123:118 */       match(RncTokenTypes.IDENTIFIER_OR_KEYWORD, "Identifier expected");
/* 124:    */     }
/* 125:    */   }
/* 126:    */   
/* 127:    */   private void d()
/* 128:    */   {
/* 129:123 */     PsiBuilder.Marker localMarker = begin();
/* 130:124 */     parseBracedGrammarContents();
/* 131:125 */     localMarker.done(RncElementTypes.DIV);
/* 132:    */   }
/* 133:    */   
/* 134:    */   private void e()
/* 135:    */   {
/* 136:129 */     PsiBuilder.Marker localMarker = begin();
/* 137:130 */     match(ASSIGN_METHOD, "'=', '|=' or '&=' expected");
/* 138:131 */     if (!parsePattern()) {
/* 139:132 */       error("Pattern expected");
/* 140:    */     }
/* 141:134 */     localMarker.done(RncElementTypes.START);
/* 142:    */   }
/* 143:    */   
/* 144:    */   protected void parseBracedGrammarContents()
/* 145:    */   {
/* 146:138 */     match(RncTokenTypes.LBRACE, "'{' expected");
/* 147:139 */     parseGrammarContents();
/* 148:140 */     match(RncTokenTypes.RBRACE, "'}' expected");
/* 149:    */   }
/* 150:    */   
/* 151:    */   protected void parseDecl(PsiBuilder paramPsiBuilder)
/* 152:    */   {
/* 153:144 */     IElementType localIElementType = paramPsiBuilder.getTokenType();
/* 154:145 */     if (localIElementType == RncTokenTypes.KEYWORD_NAMESPACE) {
/* 155:146 */       b(false);
/* 156:147 */     } else if (localIElementType == RncTokenTypes.KEYWORD_DEFAULT) {
/* 157:148 */       b(true);
/* 158:149 */     } else if (localIElementType == RncTokenTypes.KEYWORD_DATATYPES) {
/* 159:150 */       f();
/* 160:    */     }
/* 161:    */   }
/* 162:    */   
/* 163:    */   private void f()
/* 164:    */   {
/* 165:155 */     PsiBuilder.Marker localMarker = begin();
/* 166:156 */     match(RncTokenTypes.IDENTIFIER_OR_KEYWORD, "Identifier expected");
/* 167:157 */     match(RncTokenTypes.EQ, "'=' expected");
/* 168:158 */     g();
/* 169:159 */     localMarker.done(RncElementTypes.DATATYPES_DECL);
/* 170:    */   }
/* 171:    */   
/* 172:    */   private void b(boolean paramBoolean)
/* 173:    */   {
/* 174:163 */     PsiBuilder.Marker localMarker = begin();
/* 175:164 */     if (paramBoolean)
/* 176:    */     {
/* 177:165 */       match(RncTokenTypes.KEYWORD_NAMESPACE, "'namespace' expected");
/* 178:166 */       matches(RncTokenTypes.IDENTIFIER_OR_KEYWORD);
/* 179:    */     }
/* 180:    */     else
/* 181:    */     {
/* 182:168 */       match(RncTokenTypes.IDENTIFIER_OR_KEYWORD, "Identifier expected");
/* 183:    */     }
/* 184:170 */     match(RncTokenTypes.EQ, "'=' expected");
/* 185:171 */     g();
/* 186:172 */     localMarker.done(RncElementTypes.NS_DECL);
/* 187:    */   }
/* 188:    */   
/* 189:    */   private void g()
/* 190:    */   {
/* 191:176 */     match(NS_URI_LITERAL, "Namespace URI or 'inherit' expected");
/* 192:    */   }
/* 193:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.compact.parser.DeclarationParsing

 * JD-Core Version:    0.7.0.1

 */